package com.myBase.core.base.consts;

/**
 * 返回数据 的 封装对象
 * 
 * @author gebao
 * 
 */
public class ResultData<T> implements java.io.Serializable {

    private static final long serialVersionUID = 4917480918640310535L;

    private String code;// 返回码

    private String msg;// 描述

    private T data;// 数据对象

    public ResultData() {
    }

    public ResultData(String code) {
        this.code = code;
    }

    public ResultData(ResultData<Object> resultData) {
        this.code = resultData.getCode();
        this.msg = resultData.getMsg();
    }

    public ResultData(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setCode(ErrorMsgEnum errorMsgEnum) {
        this.code = errorMsgEnum.getCode();
        this.msg = errorMsgEnum.getMsg();
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public boolean isSuccessful() {
        return ErrorMsgEnum.SUCCESS.getCode().equals(this.code);
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("ResultData [code=");
        builder.append(code);
        builder.append(", msg=");
        builder.append(msg);
        builder.append(", data=");
        builder.append(data);
        builder.append("]");
        return builder.toString();
    }
}
